import request from '@/utils/request'
import { ObjectType, ResponseDataPromise } from 'typings/interfaces'
import * as proxy from '@/constants/proxy'
import { Pagination } from '@/components/Records/types'

export const fetchRecordsRequest = (
  pagination: Omit<Pagination, 'total'>,
  data: ObjectType
): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-en-fe-toll-register/page',
    method: 'post',
    data,
    params: pagination,
  })

export const createRecordRequest = (data: ObjectType): ResponseDataPromise<string> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-en-fe-toll-register',
    method: 'post',
    data,
  })

export const editRecordRequest = (data: ObjectType): ResponseDataPromise<boolean> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-en-fe-toll-register',
    method: 'put',
    data,
  })

export const deleteRecordsRequest = (ids: string[]): ResponseDataPromise<boolean> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-en-fe-toll-register`,
    method: 'delete',
    data: ids,
  })

export const getYearBySectionAbbr = (params: ObjectType) =>
  request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-en-fe-toll-register/getYearBySectionAbbr`,
    method: 'get',
    params,
  })

export const deleteDataByYear = (data): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-en-fe-toll-register/deleteDataByYear',
    method: 'post',
    data,
  })

export const importIsExists = (params: ObjectType) =>
  request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-en-fe-toll-register/importIsExists`,
    method: 'get',
    params,
  })
